package com.example.express.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Objects;

@Entity
@DynamicUpdate
public class ExpressSheet {
    private String id;
    private int type;
    private Double weight;
    private Double tranFee;
    private Double packageFee;
    private Double insuFee;
    private String accepter;
    private String deliver;
    private Timestamp accepteTime;
    private Timestamp deliveTime;
    private String acc1;
    private String acc2;
    private Integer status;
    private CustomerInfo sender;
    private CustomerInfo reveiver;
    private Collection<TransPackageContent> transPackageContents;

    @Id
    @Column(name = "ID")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "Type")
    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Basic
    @Column(name = "Weight")
    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    @Basic
    @Column(name = "TranFee")
    public Double getTranFee() {
        return tranFee;
    }

    public void setTranFee(Double tranFee) {
        this.tranFee = tranFee;
    }

    @Basic
    @Column(name = "PackageFee")
    public Double getPackageFee() {
        return packageFee;
    }

    public void setPackageFee(Double packageFee) {
        this.packageFee = packageFee;
    }

    @Basic
    @Column(name = "InsuFee")
    public Double getInsuFee() {
        return insuFee;
    }

    public void setInsuFee(Double insuFee) {
        this.insuFee = insuFee;
    }

    @Basic
    @Column(name = "Accepter")
    public String getAccepter() {
        return accepter;
    }

    public void setAccepter(String accepter) {
        this.accepter = accepter;
    }

    @Basic
    @Column(name = "Deliver")
    public String getDeliver() {
        return deliver;
    }

    public void setDeliver(String deliver) {
        this.deliver = deliver;
    }

    @Basic
    @Column(name = "AccepteTime")
    public Timestamp getAccepteTime() {
        return accepteTime;
    }

    public void setAccepteTime(Timestamp accepteTime) {
        this.accepteTime = accepteTime;
    }

    @Basic
    @Column(name = "DeliveTime")
    public Timestamp getDeliveTime() {
        return deliveTime;
    }

    public void setDeliveTime(Timestamp deliveTime) {
        this.deliveTime = deliveTime;
    }

    @Basic
    @Column(name = "Acc1")
    public String getAcc1() {
        return acc1;
    }

    public void setAcc1(String acc1) {
        this.acc1 = acc1;
    }

    @Basic
    @Column(name = "Acc2")
    public String getAcc2() {
        return acc2;
    }

    public void setAcc2(String acc2) {
        this.acc2 = acc2;
    }

    @Basic
    @Column(name = "Status")
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ExpressSheet that = (ExpressSheet) o;
        return type == that.type &&
                Objects.equals(id, that.id) &&
                Objects.equals(weight, that.weight) &&
                Objects.equals(tranFee, that.tranFee) &&
                Objects.equals(packageFee, that.packageFee) &&
                Objects.equals(insuFee, that.insuFee) &&
                Objects.equals(accepter, that.accepter) &&
                Objects.equals(deliver, that.deliver) &&
                Objects.equals(accepteTime, that.accepteTime) &&
                Objects.equals(deliveTime, that.deliveTime) &&
                Objects.equals(acc1, that.acc1) &&
                Objects.equals(acc2, that.acc2) &&
                Objects.equals(status, that.status);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, type, weight, tranFee, packageFee, insuFee, accepter, deliver, accepteTime, deliveTime, acc1, acc2, status);
    }

    @ManyToOne
    @JoinColumn(name = "Sender", referencedColumnName = "ID")
    public CustomerInfo getSender() {
        return sender;
    }

    public void setSender(CustomerInfo sender) {
        this.sender = sender;
    }

    @ManyToOne
    @JoinColumn(name = "Recever", referencedColumnName = "ID")
    public CustomerInfo getReveiver() {
        return reveiver;
    }

    public void setReveiver(CustomerInfo reveiver) {
        this.reveiver = reveiver;
    }

    @JsonIgnore
    @OneToMany(mappedBy = "expressSheet")
    public Collection<TransPackageContent> getTransPackageContents() {
        return transPackageContents;
    }

    public void setTransPackageContents(Collection<TransPackageContent> transPackageContents) {
        this.transPackageContents = transPackageContents;
    }
}
